package lulu.taglib.basic;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Created by IntelliJ IDEA.
 * User: Ivan
 * Date: 2010-6-14
 * Time: 12:51:52
 */
public class Link extends TagSupport {

    private String href = null;

    public void setHref(String href) {
        this.href = href;
    }
    
    public int doStartTag() throws JspException {
        try {
            JspWriter out = pageContext.getOut();
            out.print(getLinkHref());
        } catch (Exception e) {
            throw new JspException(e);
        }

        return EVAL_PAGE;
    }

    private String getLinkHref() {
        HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
        
        String path = req.getContextPath();
        String basePase =  req.getScheme() + "://" +  req.getServerName() + ":" +  req.getServerPort() + path + "/" + href;
        
        return warp(basePase);
    }
    
    private String warp(String str){
    	            return "<link rel=\"stylesheet\" href=\"" + str + "\" type=\"text/css\"/>";
    }
}
